<template>
  <div class="selectEnterList-con">
    <PageItemQueryCard :eventPool="eventPool" :tableList="tableList" :QueryCardConfig="QueryConfig"
    :headerConfig="headerConfig"></PageItemQueryCard>
  </div>
</template>

<script>
// import PageItemQueryCard from './PageItemQueryCard.vue'
import configData from './../utils/configData'
import getDataForDB from '@/api/qsbserviceEnterprise'

const formItemAttr_ = { labelCol: { xxl: 5, xl: 12 }, wrapperCol: { xxl: 16, xl: 10 } }
const data_ = [
  {
    id: '1',
    entName: 'John Brown',
    lisenceCreditCode: '￥300,000.00',
    legalName: 'New York No. 1 Lake Park',
  },
  {
    id: '2',
    entName: 'Jim Green',
    lisenceCreditCode: '￥1,256,000.00',
    legalName: 'London No. 1 Lake Park',
  },
  {
    id: '3',
    entName: 'Joe Black',
    lisenceCreditCode: '￥120,000.00',
    legalName: 'Sidney No. 1 Lake Park',
  },
  {
    id: '4',
    entName: 'John Brown',
    lisenceCreditCode: '￥300,000.00',
    legalName: 'New York No. 1 Lake Park',
  },
  {
    id: '5',
    entName: 'Jim Green',
    lisenceCreditCode: '￥1,256,000.00',
    legalName: 'London No. 1 Lake Park',
  },

]


export default {
  name: 'selectEnterList',
  props: {
    coloseEvent: { type: Function },
    serviceInfo: {type:Object}
  },
  // components: { PageItemQueryCard },
  data() {
    return {
      code:'',
      headerConfig: {
        show: true,
        title: '企业列表选择',
        btnList: []
      },
      tableList: [
        // otherAttrs:{rowSelection:tempEvent}
        { tabName: '全部（11）', columns: configData.qylbTableColumns, dataSource: [], showRowSelection: true, isSingleChoice: true ,current:1,pageSize:10,total:0,pageSizeOptions:['10', '20', '30']},

      ],
      QueryConfig: {

        pageFormConfig:{
          defaultFormConfig:{
            columnCount:1,
            layout:'horizontal',
            labelCol:{span: 6},
            wrapperCol:{span: 18},
            rowAttr:{
              // type:'',
              // justify:'',
              // gutter:'',
              // align:'',
            },
            celAttr:{
              // flex:'',
              // offset:'',
              // order:'',
              // pull:'',
              // push:'',
              span:20,
              // xxl:{},
            }
          },
          formConfig:{
            // columnCount:4,
            // layout:'horizontal',
            // labelCol:{span: 6},
            // wrapperCol:{span: 18},
            // rowAttr:{
            //   // type:'',
            //   // justify:'',
            //   // gutter:'',
            //   // align:'',
            // },
            // celAttr:{
            //   // flex:'',
            //   // offset:'',
            //   // order:'',
            //   // pull:'',
            //   // push:'',
            //   span:6,
            //   // xxl:{},
            // }
          },
        },
        btnGroupConfig: {
          btnList: [
            { isDefault: true, label: '确定', eventKey: 'exportPage', isEvent: true, itemAttr: { icon: 'check' } },
          ],
        },
        formListConfig: {
          formList: [
            { isDefault: true, enName: 'entName', cnName: '企业名称', type: 'input', value: '', itemAttr: { placeholder: '请输入企业名称', allowClear: true }, formItemAttr: formItemAttr_ },
            // { isDefault: true, enName: 'legalName', cnName: '订单号', type: 'input', value: '', itemAttr: { placeholder: '请输入订单号', allowClear: true }, formItemAttr: formItemAttr_ },
          ]
        }
      },
      selectDataInfo:{}
    }
  },
  watch: {
    serviceInfo: {
      handler(val) {
        if(Object.prototype.toString.call(val)==='[object Object]'){
          const {code} = val
          this.code = code
          if(code=='1008'){
            this.headerConfig.btnList = [{label:'有未完成发票业务的企业，可在发票业务完成后再进行税务核定方式变更中请.', itemAttr:{type:'dashed', ghost:true, icon:'', style:'color:#ff4d4f;'}}]
          }else{
            this.headerConfig.btnList = []
          }
          this.getData('',code)
        }
      },
      deep: true,
      immediate: true
    },

  },
  methods: {
    eventPool(index, type, data,...args) {
      // type 的值有 query  tabChange  tableChange  tableSelect  tableSelectAll  btnClick  query-*
      const typeList = {
        tableSelect: this.tableSelectEvent,
        query:this.query,
        'query-exportPage':this.queryExportPage
      }
      // console.log(' 列表页面 eventPool==》', index, type, data,...args);
      typeList[type] && typeList[type](index,data)
    },
    query(index,data){
      // console.log('query=====>',index,data);
      this.getData(data.data.entName,this.code)
    },
    getData(entName,code){
      getDataForDB('待申请服务企业列表查询',{"entName": entName,"opType": code}).then(res=>{
        // console.log('待申请服务企业列表查询===>',res);
        // tableList\\
        if(res.code===200){
          this.tableList[0].dataSource = res.result
          this.tableList[0].total = res.result.length
        }
      })

    },
    tableSelectEvent(index,data){
      this.selectDataInfo = {...data[0]}
    },
    queryExportPage(index_,data){
      // console.log('确定下一步==》',  this.selectDataInfo );
      if(this.selectDataInfo && Object.keys(this.selectDataInfo).length >0){

        if(this.code=='1008'){
          this.checkData(this.selectDataInfo.id,(res)=>{
            const {success,result} = res
            if(success){
              if(result==0){
                this.$message.warning(`您选择的【${this.selectDataInfo.entName}(${this.selectDataInfo.id})】有未完成的发票业务，请在业务完成后再进行税务核定变更！`)
              }else{
                this.coloseEvent(this.selectDataInfo)
              }
            }else{
              this.$message.error('当前所选数据进行税务变更校验失败，系统拒绝选择此数据！！')
            }
            // console.log('@@@@@@@@@@@@@@',res);
          })
        }else{
          this.coloseEvent(this.selectDataInfo)
        }
      } else {
        this.$message.warning('必须选择一个企业数据！！')
      }
    },
    checkData(entId_,backFun){
      const param = {entId:entId_}
      getDataForDB('判断企业是否可以税务变更',param).then(res=>{
        backFun&backFun(res)
      })
    }
  }
}
</script>

<style lang="less">
.selectEnterList-con{
  .page-item-query-card-con {
    .card-body{
      .page-item-query-card-body{
        .table{
          .ant-table-wrapper{
            .ant-spin-nested-loading{
              .ant-spin-container{
                .ant-table{
                  .ant-table-content{
                    .ant-table-scroll{
                      .ant-table-header{
                        .ant-table-fixed{
                          .ant-table-thead{
                            tr{
                              .ant-table-selection-column{
                                .ant-table-header-column{
                                  display: none;
                                }
                              }
                            }
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}
</style>
